package com.example.leoss.zhuye.search;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.example.leoss.Duquzifu.Data;
import com.example.leoss.R;
import com.example.leoss.zhuye.img_tongxu_phone.Tongxu_img_Activity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SearchAdpat  extends BaseAdapter {

    Context context;
    List<Data> list;

    public SearchAdpat(List<Data> list , SearchActivity context ) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {

        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int i, View convertView, ViewGroup parent) {
        @SuppressLint("ViewHolder")
        View view= LayoutInflater.from(context).inflate(R.layout.serch_items,null,false);

        ImageView imageView = view.findViewById(R.id.img_view_layout_phome1);
        TextView phone = view.findViewById(R.id.id_layouttx_tv_phone1);
        TextView   name = view.findViewById(R.id.id_layouttx_tv_name1);

        imageView.setImageResource(list.get(i).getIcon());
        phone.setText(this.list.get(i).getPhome());
        name.setText(this.list.get(i).getName());



        imageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Toast.makeText(context,"img"+i,Toast.LENGTH_LONG).show();
                Intent intent=new Intent(context, Tongxu_img_Activity.class);
                intent.putExtra("ID",list.get(i).getId());
                intent.putExtra("name",list.get(i).getName());
                intent.putExtra("phome",list.get(i).getPhome());
                intent.putExtra("address",list.get(i).getAddress());
                intent.putExtra("major",list.get(i).getMajar());
                intent.putExtra("qq",list.get(i).getQq());
                intent.putExtra("sex",list.get(i).getSex());
                context.startActivity(intent);
            }
        });

        return view;
    }
}
